<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>table</title>
    <style>
        td{
            padding: 10px 20px;
        }
        table,td{
            border-collapse: collapse;
        }
        table tr:nth-child(even){
            background-color: azure;
        }
        table tr:nth-child(odd){
            background-color: bisque;
        }
    </style>
</head>
<body>
    <table border="1">
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </table>
    <script>
        let tds = document.querySelectorAll('td')
        tds.forEach(item => {
            item.onclick = function() { 
                this.style.backgroundColor = 'red'
             }
        });
    </script>
</body>
</html>